namespace core {
    export class Log {

        public static getFunctionName(func: any) {
            var name = ('' + func).match(/function\s*([\w\$]*)\s*\(/);
            return name && name[1];
        }

        public static trace2() {
            var stack = [],
                caller = arguments.callee.caller;

            while (caller) {
                stack.unshift(Log.getFunctionName(caller));
                caller = caller && caller.caller;
            }

            console.log('functions on stack:' + '\n' + stack.join('\n'));
        }

        public static trace() {
            var caller = arguments.callee.caller;
            var i = 0;
            var count = 20;
            console.log("***----------------------------------------  ** " + (i + 1));
            while (caller && i < count) {
                console.log(caller.toString());
                //console.log(Log.getFunctionName(caller))
                caller = caller.caller;
                i++;
                console.log("***---------------------------------------- ** " + (i + 1));
            }
        }

        public static error2(...optionalParams: any[]): void {
            if (App.DebugUtils.isDebug) {
                optionalParams[0] = "[DebugLog]" + optionalParams[0] + " at (c:\\code\\server\\trunk\\branch_0\\client\\Titles\\src\\core\\utils\\Log.ts:18:54)";
                console.log.apply(console, optionalParams);
                //Log.trace()
            }
        }


        public static error(arg) {
            try {
                throw new Error();
            } catch (e) {
                console.log(arg + "\n" + e.stack);
                var loc = e.stack.replace(/Error\n/).split(/\n/)[1].replace(/^\s+|\s+$/, "");
                console.log("Location: " + loc + "");
            }
        }

    }
}